import {request } from 'ice';
import {API_URL} from './ApiUrl';
import {Message} from '@alifd/next';

/**
 * 首页考试提示-列表接口
 * @param {*} params 
 */
async function listPage(params) {
    try {
        const response = await request.post(API_URL.API_EXAM_TIP_LIST, params);
        if(response.status == 0){
          return response.data;
        }else{
          const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
          Message.error(msg)
        }
    } catch (error) {
      console.error(error);
    }
}

/**
 * 查询首页考试提示-详情
 * @param {*} params 
 */
async function detail(params) {
  try {
      const response = await request.post(API_URL.API_EXAM_TIP_DETAIL, {id: params});
      if(response.status == 0){
        return response.data;
      }else{
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
      }
  } catch (error) {
    console.error(error);
  }
}
async function detailV(params) {
  try {
      const response = await request.post(API_URL.API_EXAM_TIP_DETAIL_V, {id: params});
      if(response.status == 0){
        return response.data;
      }else{
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
      }
  } catch (error) {
    console.error(error);
  }
}
/**
 * 新增 首页考试提示
 * @param {*} params 
 */
async function add(params) {
  try {
      const response = await request.post(API_URL.API_EXAM_TIP_ADD, params);
      if(response.status == 0){
        return true;
      }else{
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
        return false;
      }
  } catch (error) {
    console.error(error);
  }
  return false;
}

/**
 * 修改首页考试提示-信息
 * @param {*} params 
 */
async function update(params) {
  try {
      const response = await request.post(API_URL.API_EXAM_TIP_UPDATE, params);
      if(response.status == 0){
        return true;
      }else if(response.status == 41501){
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
        return false;
      }else {
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
        return false;
      }
  } catch (error) {
    console.error(error);
  }
  return false;
}

/**
 * 删除 首页考试提示
 * @param {*} params 
 */
async function deleteExamTip(params) {
  try {
      const response = await request.post(API_URL.API_EXAM_TIP_DELETE, {id: params});
      if(response.status == 0){
        return true;
      }else{
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
        return false;
      }
  } catch (error) {
    console.error(error);
  }
  return false;
}

/**
 * 发布 首页考试提示
 * @param {*} params 
 */
async function publish(params) {
  try {
      const response = await request.post(API_URL.API_EXAM_TIP_PUBLISH, {id: params});
      if(response.status == 0){
        return true;
      }else{
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
        return false;
      }
  } catch (error) {
    console.error(error);
  }
  return false;
}
/**
 * 下架 首页考试提示
 * @param {*} params 
 */
async function downShelf(params) {
  try {
      const response = await request.post(API_URL.API_EXAM_TIP_DOWN_SHELF, {id: params});
      if(response.status == 0){
        return true;
      }else{
        const msg = response.msg ? response.msg : "服务忙, 请稍后再试!"
        Message.error(msg)
        return false;
      }
  } catch (error) {
    console.error(error);
  }
  return false;
}
export {listPage, detail, detailV, add, update, deleteExamTip, publish, downShelf}